package com.itheima.test04;

public class Test {

    public static void main(String[] args) {
/*        useCat(new Cat());
        useDog(new Dog());*/
   /*     useAnimal(new Dog());
        useAnimal(new Cat());*/
        Animal a = getAnimal();//Animal a= new Dog();
        a.eat();
        Dog d= (Dog) a;
        d.watchHome();

    }
    //生产动物
    public static Animal getAnimal(){
       //return new Dog();
       return new Cat();
    }
    //使用猫
    public static void useCat(Cat cat) {
        cat.eat();
    }

    //使用狗
    public static void useDog(Dog dog) {
        dog.eat();
    }

    //需要参数时,使用父类类型作为参数的类型
    public static void useAnimal(Animal a) {
        a.eat();//抽象类的子类对象
    }




}

abstract class Animal {
    abstract void eat();
}

class Dog extends Animal {
    @Override
    void eat() {
        System.out.println("狗吃肉");
    }
    public void watchHome(){
        System.out.println("看家");
    }
}

class Cat extends Animal {
    @Override
    void eat() {
        System.out.println("猫吃鱼");
    }
}


